package com.juxfe.bookmanagement.service;

import com.juxfe.bookmanagement.mapper.BookMapper;
import com.juxfe.bookmanagement.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookMapper bookMapper;

    @Override
    public boolean addBook(Book book) {
        int result = bookMapper.insert(book);
        return result > 0;
    }

    @Override
    public boolean updateBook(Book book) {
        int result = bookMapper.update(book);
        return result > 0;
    }

    @Override
    public boolean deleteBook(Integer id, Integer userId) {
        int result = bookMapper.deleteById(id, userId);
        return result > 0;
    }

    @Override
    public Book getBookById(Integer id) {
        return bookMapper.findById(id);
    }

    @Override
    public List<Book> getBooksByUserId(Integer userId) {
        return bookMapper.findByUserId(userId);
    }

    @Override
    public List<Book> getBooksByCondition(Integer userId, String keyword) {
        return bookMapper.findByCondition(userId, keyword);
    }
}
